<template>
  <div>
      <p>用户名：<input type="text" v-model="name"></p>
      <p>密码：<input type="text" v-model="password"></p>
      <p><button @click="login">登录</button></p>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return{
            name:'',
            password:'',
        }   
    },
    created(){

    },
    methods:{
        login(){
            var formdata= new FormData()
            formdata.append('name',this.name)
            formdata.append('password',this.password)
            axios.post('http://127.0.0.1:8000/myapp/login/',formdata).then(res=>{
                console.log(res.data)
                if(res.data.code==200){
                    sessionStorage.setItem('name',res.data.name)
                    sessionStorage.setItem('id',res.data.id)

                    window.location.href='/show'
                }
            })
        }
    }
}
</script>

<style>

</style>